package br.com.cnpv.modelo.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import com.sun.faces.mgbean.ManagedBeanPreProcessingException.Type;

@Entity
@Table(name="usuario")
@NamedQueries(
		{ 
			@NamedQuery(name="Usuario.login", query="select u from Usuario u where u.dsLogin = :login and u.senha = :senha"),
			@NamedQuery(name="Usuario.buscar", query="select u from Usuario u where u.nmUsuario like :nome"),
			@NamedQuery(name="Usuario.listar", query="select u from Usuario u order by u.nmUsuario asc "),
			@NamedQuery(name="Usuario.buscarByNome", query="select u from Usuario u where u.nmUsuario like :clausula"),
			@NamedQuery(name="Usuario.buscarByNmPerfil", query="select u from Usuario u where u.perfil.nmPerfil like :clausula"),
			@NamedQuery(name="Usuario.buscarByAssociacao", query="select u from Usuario u where u.associacao.razaoSocial like :clausula"),
			
		}
	)
public class Usuario {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id")
	private Integer id;
	
	@Column(name="nm_usuario")
	private String nmUsuario;
	
	@Column(name="ds_login")
	private String dsLogin;
	
	@Column(name="senha")
	private String senha;
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="id_associacao", insertable=false, updatable=false, referencedColumnName="id")
	private Associacao associacao;
	
	@Column(name="id_associacao", insertable=true, updatable=true)
	private Integer idAssociacao;
	
	@Column(name="dt_incl")
	private Date dtIncl;
	
	@Column(name="dt_alter")
	private Date dtAlter;
	
	@Column(name="dt_inat")
	private Date dtInat;
	
	@OneToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="id_perfil", insertable=false, updatable=false, referencedColumnName="id")
	private Perfil perfil;
	
	@Column(name="id_perfil", insertable=true, updatable=true)
	private Integer idPerfil;

	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNmUsuario() {
		return nmUsuario;
	}

	public void setNmUsuario(String nmUsuario) {
		this.nmUsuario = nmUsuario;
	}

	public String getDsLogin() {
		return dsLogin;
	}

	public void setDsLogin(String dsLogin) {
		this.dsLogin = dsLogin;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public Integer getIdAssociacao() {
		return idAssociacao;
	}

	public void setIdAssociacao(Integer idAssociacao) {
		this.idAssociacao = idAssociacao;
	}

	public Date getDtIncl() {
		return dtIncl;
	}

	public void setDtIncl(Date dtIncl) {
		this.dtIncl = dtIncl;
	}

	public Date getDtAlter() {
		return dtAlter;
	}

	public void setDtAlter(Date dtAlter) {
		this.dtAlter = dtAlter;
	}

	public Date getDtInat() {
		return dtInat;
	}

	public void setDtInat(Date dtInat) {
		this.dtInat = dtInat;
	}

	public Associacao getAssociacao() {
		return associacao;
	}

	public void setAssociacao(Associacao associacao) {
		this.associacao = associacao;
	}

	public Perfil getPerfil() {
		return perfil;
	}

	public void setPerfil(Perfil perfil) {
		this.perfil = perfil;
	}

	public Integer getIdPerfil() {
		return idPerfil;
	}

	public void setIdPerfil(Integer idPerfil) {
		this.idPerfil = idPerfil;
	}

}